from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from d115.mixins import *
from d115.products.models import *

class PCatAdmin(admin.ModelAdmin):
    list_display = ("name", "slug", "position")
    list_display_links = ("name", "slug", )
    search_fields = ("name", )

class ProductAdmin(NomenclatureAdminMixin):
    list_display = ("category", "name", "slug", "position", "price", "discount", "final_price", "savings")
    list_display_links = ("name", "slug", )
    list_filter = ("category", "active")
    class Media:
        js = ('/ckeditor/ckeditor.js', '/media/js/ckedit3.js')

class OrderAdmin(AuditAdminMixin):
    list_display = ("created", "user", "product", "amount", "payment_method", "status")
    list_filter = ("product", "payment_method", "status")
    search_fields = ("user__username", "user__firstname", "user__lastname", "comments")
    def has_add_permission(self, request):
        return False

try:
    admin.site.unregister(ProductCategory)
except:
    pass
admin.site.register(ProductCategory, PCatAdmin)
try:
    admin.site.unregister(Product)
except:
    pass
admin.site.register(Product, ProductAdmin)
try:
    admin.site.unregister(ProductOrder)
except:
    pass
admin.site.register(ProductOrder, OrderAdmin)
